package com.briup.mt.service.impl;

import com.briup.mt.bean.BaseRolePrivilege;
import com.briup.mt.bean.BaseRolePrivilegeExample;
import com.briup.mt.dao.BaseRolePrivilegeMapper;
import com.briup.mt.service.IBaseRolePrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: app03
 * @description: 用户信息实现类
 * @author: charles
 * @create: 2020-12-15 16:41
 **/
@Service

public class BaseRolePrivilegeImpl implements IBaseRolePrivilegeService{

    @Resource
    private BaseRolePrivilegeMapper baseRolePrivilegeMapper;

    @Override
    public List<BaseRolePrivilege> query(Long roleId,Long privilegeId) {
        // 模板
        BaseRolePrivilegeExample example = new BaseRolePrivilegeExample();
        if(!StringUtils.isEmpty(roleId)){
            example.createCriteria().andRoleIdEqualTo(roleId);
        }
        if(!StringUtils.isEmpty(privilegeId)){
            example.createCriteria().andPrivilegeIdEqualTo(privilegeId);
        }

        List<BaseRolePrivilege> list = baseRolePrivilegeMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(BaseRolePrivilege baseRolePrivilege) {
        // 如果userInfo中存在id属性，表示更新；否则保存
        if(baseRolePrivilege.getId() == null){
            baseRolePrivilegeMapper.insert(baseRolePrivilege);
        } else {
            baseRolePrivilegeMapper.updateByPrimaryKey(baseRolePrivilege);
        }
    }

    @Override
    public void deleteById(long id) {
        baseRolePrivilegeMapper.deleteByPrimaryKey(id);
    }
}
